package com.ffms.servlet;

import com.ffms.dao.BankDao;
import com.ffms.dao.FamilyMemberDao;
import com.ffms.dao.impl.BankDaoImpl;
import com.ffms.dao.impl.FamilyMemberDaoImpl;
import com.ffms.entity.Bank;
import com.ffms.entity.FamilyMember;
import com.ffms.entity.Shouru;
import com.ffms.service.AdminService;
import com.ffms.service.impl.AdminServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

//查询到所有账户
@WebServlet("/AllBankServlet")
public class AllBankServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Object user = request.getSession().getAttribute("user");
        BankDao bankDao = new BankDaoImpl();
        List<Bank> bankList;
        if (user instanceof FamilyMember) {
            FamilyMember familyMember = (FamilyMember) user;
            bankList = bankDao.findBankByMid(familyMember.getSid());
        } else {
            bankList = bankDao.findBank();
        }
        FamilyMemberDaoImpl familyMemberDao = new FamilyMemberDaoImpl();
        List<FamilyMember> all = familyMemberDao.findAll();
        //3.跳转到显示成员页面
        request.setAttribute("bankList", bankList);
        request.setAttribute("members", all);
        request.getRequestDispatcher("admin/bankList.jsp").forward(request, response);
    }
}
